package com.bean;

import java.sql.SQLException;
import java.util.Collection;

import javax.servlet.http.HttpServletRequest;

import org.apache.catalina.User;

import com.conf.Parameters;
import com.domain.UsuariosDomain;
import com.exception.UsuarioYaExisteException;
import com.vo.Usuarios;

public class LoginBean extends AbstractBean {
	
	public LoginBean(){}
	
	public boolean login(HttpServletRequest req){
		String usr=req.getParameter("usr").toString();
		String pwd=req.getParameter("pwd").toString();
		
		try {
			Usuarios user=UsuariosDomain.getInstance().findUsuario(usr,pwd);
			if(user!=null){
				com.conf.User u=new com.conf.User();
				u.setPerfil(user.getIdTipoUsuario());
				req.getSession().setAttribute(Parameters.USER_ATTRIBUTE,u);
				return true;
			}
		} catch (Exception e) {
			this.addError(e);
		}
		return false;
	}
}
